package asia.doing.service.admin;

import asia.doing.common.utils.UUIDUtils;
import asia.doing.entity.Category;
import asia.doing.mapper.CategoryMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service(value = "manageCategoryService")
public class ManageCategoryService {
    @Resource
    private CategoryMapper categoryMapper;

    public void add(Category category){
        // 使用uuid作为唯一性的id进行插入数据
        category.setId(UUIDUtils.getUUIDInOrderId());
        categoryMapper.insert(category);
    }

    public void deleteById(Long id){
        categoryMapper.deleteById(id);
    }

    public void deleteBatch(List<Long> ids){
        for(Long id : ids){
            categoryMapper.deleteById(id);
        }
    }

    public void updateById(Category category){
        categoryMapper.updateById(category);
    }

    public Category selectById(Long id){
        return categoryMapper.selectById(id);
    }


    public List<Category> selectAll(Category category){
        return categoryMapper.selectAll(category);
    }

    public PageInfo<Category> selectPage(Category category, Integer pageNum, Integer pageSize){
        PageHelper.startPage(pageNum,pageSize);
        List<Category> list = categoryMapper.selectAll(category);
        return PageInfo.of(list);
    }
}
